using System.Configuration;

namespace Rioshu.Web.ViewStateHandlers
{
    public class NameTypeElementCollection : ConfigurationElementCollection
    {
        public new NameTypeElement this[string name]
        {
            get { return BaseGet(name) as NameTypeElement; }
        }

        public NameTypeElement this[int index]
        {
            get { return BaseGet(index) as NameTypeElement; }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemove(index);
                BaseAdd(index, value);
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new NameTypeElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((NameTypeElement) element).Name;
        }
    }
}